package com.mg.axechen.room

import android.content.Context
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.mg.axechen.room.bean.User
import com.mg.axechen.room.db.AppDataBase
import kotlinx.coroutines.launch

class UserViewModel: ViewModel() {

    // 获取用户列表的LiveData
    var userLiveData: MutableLiveData<MutableList<User>> = MutableLiveData()

    fun getUserList(context: Context) {
        viewModelScope.launch {
            val getUserListener = AppDataBase.getInstance(context).userDao().getUsers()
            userLiveData.postValue(getUserListener)
        }

    }

}